const pool = require('./db.js')
class userDao {
  // 根据账号与密码，查询是否存在这个用户
  async getUser(account,pwd){
    try{
      let result = {}
      result = await pool.execute('select * from users where user_account=? and user_pwd=?',[account,pwd])
      return result
    }catch(err){
      console.log('出错:' + err)
    }
  }

  // 新增用户 输入用户账号，密码，用户名
  async addUser(name,account,pwd){
    try{
      let result = await pool.execute('insert users(user_name,user_pwd,user_account) values(?,?,?)',[name,pwd,account])
      return result
    }catch(err){
      console.log('出错:' + err)
    }
  }
  // 根据用户id获取用户信息
  async findUser(id){
    try{
      let result = await pool.execute('select * from users where user_id=?',[id])
      return result
    }catch(err){
      console.log('出错:' + err)
    }
  }
}

module.exports = new userDao()